#include<stdio.h>

int joseph(int k,int m){
	int n,a=1;
	for(n=1;n<=k;n++){
		a = (a+m-1)%(2*k-n+1);
		if(a==0)
		    a = 2*k-n+1;
		if(a<=k&&a>=1)
		    return 0;
	}
	return 1;
}

void calm(int k){
	int m;
	for(m=k+1;;m++){
		if(joseph(k,m)){
			printf("%d\n",m);
			break;
		}
	}
}

int main(){
	int k;
	while(scanf("%d",&k),k){
		if(!k)
		    break;
		switch(k){
			case 1:
				printf("%d\n",2);
				break;
			case 2:
				printf("%d\n",7);
				break;
			case 3:
				printf("%d\n",5);
				break;
			case 4:
				printf("%d\n",30);
				break;
			case 5:
				printf("%d\n",169);
				break;
			case 6:
				printf("%d\n",441);
				break;
			case 7:
				printf("%d\n",1872);
				break;
			case 8:
				printf("%d\n",7632);
				break;
			case 9:
				printf("%d\n",1740);
				break;
			case 10:
				printf("%d\n",93313);
				break;
			case 11:
				printf("%d\n",459901);
				break;
			case 12:
				printf("%d\n",1358657);
				break;
			case 13:
				printf("%d\n",2504881);
				break;
		}
	}
	return 0;
}